const path = require('path')
const vuxLoader = require('vux-loader')
const webpack = require('webpack')
const { resolve } = require('path')
const env = require('./env')
module.exports = {
  head: {
    title: '升学在线',
    meta: [
      {
        charset: 'utf-8',
      },
      {
        name: 'referrer',
        content: 'no-referrer',
      },
      {
        name: 'format-detection',
        content: 'telephone=yes',
      },
      {
        name: 'viewport',
        content: 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no',
      },
      {
        hid: 'description',
        name: 'description',
        content: '{{escape description }}',
      },
    ],
    link: [],
    script: [
      {
        innerHTML: 'document.documentElement.style.fontSize = document.documentElement.clientWidth / 7.5 + `px`;',
        type: 'text/javascript',
      },
      {
        src: 'https://static.shengxue985.com/sxzx_app/h5/js/echarts.min.js',
      },
    ],
  },
  render: {
    resourceHints: false,
  },
  externals: {
    echarts: 'echarts',
  },
  env: {
    mallApi: env[process.env.MODE].ENV_MALL_API,
    workUrl: env[process.env.MODE].ENV_WORK_URL,
    workAppid: env[process.env.MODE].ENV_APPID,
    mallurl: env[process.env.MODE].ENV_MALLURL,
    wechatVersion: env[process.env.MODE].VERSION,
    manualUrl: env[process.env.MODE].ENV_MANUAL_URL,
  },
  router: {
    // middleware: 'stats',
    base: '/wx-yxk/',
    mode: 'hash',
  },
  loading: {
    color: '#FFAD0D',
  },
  plugins: [
    {
      src: '~/plugins/global',
      ssr: false,
    },
    {
      src: '~/plugins/vux-plugins',
      ssr: false,
    },
    {
      src: '~/plugins/auth',
      ssr: false,
    },
  ],
  build: {
    cache: true,
    parallel: true,
    styleResources: {
      less: './assets/css/base.less',
    },
    uglify: {
      uglifyOptions: {
        mangle: {
          safari10: true,
        },
      },
    },
    extend(config, { isDev, isClient }) {
      if (isDev && isClient) {
        config.module.rules.push({
          enforce: 'pre',
          test: /\.(js|vue)$/,
          loader: 'eslint-loader',
          exclude: /(node_modules)/,
        })
      }
      const configs = vuxLoader.merge(config, {
        options: {
          ssr: true,
        },
        plugins: [
          'vux-ui',
          {
            name: 'less-theme',
            path: path.join(__dirname, './styles/theme.less'),
          },
        ],
      })
      return configs
    },
  },
  modules: ['@nuxtjs/axios', '@nuxtjs/proxy'],
  /*
   ** proxy
   */
  proxy: {
    '/client-api': {
      target: 'https://app-test.shengxue985.sx985.com',
      changeOrigin: true,
      pathRewrite: {
        '^/client-api': '',
      },
    },
    // 正式的
    '/shengxueApi': {
      target: 'https://app-test.shengxue985.sx985.com',
      changeOrigin: true,
      pathRewrite: {
        '^/shengxueApi': 'shengxueApi',
      },
    },
    '/academy': {
      target: 'https://app-test.shengxue985.sx985.com',
      changeOrigin: true,
      pathRewrite: {
        '^/academy': 'academy',
      },
    },

    '/shengxue': {
      // target: 'https://app.shengxue985.com',
      target: 'https://app-test.shengxue985.sx985.com',
      changeOrigin: true,
      pathRewrite: {
        '^/shengxue': 'shengxue',
      },
    },
    '/schoolApi': {
      // target: 'https://app.shengxue985.com',
      target: 'https://api-test.sx985.com',
      changeOrigin: true,
      pathRewrite: {
        '^/schoolApi': 'api',
      },
    },
    '/mall-api': {
      target: 'https://api.test-mall.sx985.com',
      changeOrigin: true,
      pathRewrite: {
        '^/mall-api': '/api',
      },
    },
    '/mobileApi': {
      target: 'https://api-test.sx985.com',
      changeOrigin: true,
      pathRewrite: {
        '^/mobileApi': '',
      },
    },
    '/flight': {
      target: 'http://47.92.163.86:9501',
      changeOrigin: true,
      pathRewrite: {
        '^/flight': '',
      },
    },
  },
  css: ['assets/css/main.css'],
}
